package com.wisdom.benefit.jufa.guide;


import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.TextUtils;
import android.widget.TextView;

import com.wisdom.benefit.jufa.R;
import com.wisdom.benefit.jufa.base.BaseActivity;
import com.wisdom.benefit.jufa.base.BaseApplication;
import com.wisdom.benefit.jufa.main.MainActivity;
import com.wisdom.benefit.jufa.main.LoginActivity;

import androidx.appcompat.widget.AppCompatImageView;

public class SplashActivity extends BaseActivity {
    private AppCompatImageView iv_btn;
    private TextView timeTv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //倒计时
        timeTv = findViewById(R.id.splash_time_tv);
        cdTimer.start();

    }

    @Override
    protected int getLayout() {
        return R.layout.activity_splash;
    }

    @Override
    protected void initViews() {

    }

    @Override
    protected int getTitleStringRes() {
        return 0;
    }

    private CountDownTimer cdTimer = new CountDownTimer(3000, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            timeTv.setText((millisUntilFinished / 1000) + "");
        }

        @Override
        public void onFinish() {
            timeTv.setText("0");
            SharedPreferences sharedPreferences = getSharedPreferences("data", Context.MODE_PRIVATE);
            String userId = sharedPreferences.getString("isHaveLogin", "");
            String userId1 = sharedPreferences.getString("userId", "");

            BaseApplication.getContext().setUserId(userId1);
            if (TextUtils.isEmpty(userId) || userId.equals("0")) {

                Intent intent = new Intent(SplashActivity.this, LoginActivity.class);
                startActivity(intent);
            } else {
                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(intent);
            }

            finish();
        }
    };

}
